package com.ly.chatsimple.ui.chat.usecase

import com.ly.chatsimple.tcp.TcpClient
import com.ly.data.MessageProtobuf.Msg
import com.ly.data.MessageProtobuf.MsgBody

class ChatSendUseCase {

    suspend fun sendMsg(msg: String) = TcpClient.sendMsg(createMsgObj(msg))

    private fun createMsgObj(msg: String): Msg {
        val timestamp = System.currentTimeMillis()
        val body = MsgBody.newBuilder()
            .setContent(msg)
            .build()
        return Msg.newBuilder()
            .setMsgId(timestamp)
            .setTimestamp(timestamp)
            .setBody(body)
            .setReceiver("app-client-receiver")
            .setSender(TcpClient.ip)
            .build()
    }
}